<template>
	<view style="height: 100%">
		<!-- pages/logistics/logistics.wxml -->
		<view class="logistics-container">
			<view class="list v-center">
				<view class="left-list">
					<image mode="aspectFill" :src="img ? img : '/static/files/images/default.png'"></image>
				</view>
				<view v-if="hasStatus" class="right-list">
					<view class="row1">状态：{{ status }}</view>
					<view class="row2">{{ com }} 【{{ expresscode }}】</view>
				</view>
				<view v-else class="right-list">
					<view class="grey">待揽件</view>
					<view class="grey">请耐心等待哦~~~</view>
				</view>
			</view>
			<view class="logistics-list">
				<view v-if="!hasStatus" class="grey">待揽件~~~</view>
				<view class="list-item nowrap" v-for="(item, idx) in statusList" :key="idx">
					<view :style="'color:' + (idx == 0 ? color : '#aaa')" class="item-time">{{ item.time }}</view>

					<view class="item-icon">
						<text v-if="idx == 0" :style="'background:' + color + ';color:#fff;'" class="icon"></text>
						<text v-else style="border: 1px #aaa solid" class="icon"></text>
					</view>

					<view class="item-content">
						<view :style="'color:' + (idx == 0 ? color : '#aaa')" class="context">
							{{ item.status }}
						</view>
					</view>
				</view>
			</view>
		</view>

		<floatIcon></floatIcon>
	</view>
</template>

<script>
	import floatIcon from '@/component/floatIcon/floatIcon';
	// pages/logistics/logistics.js
	var util = require('../../utils/util.js');
	var api = require('../../utils/prom.js');
	export default {
		components: {
			floatIcon
		},
		data() {
			return {
				color: app.globalData.color,
				com: '圆通',
				expresscode: 'YT4432108061052',
				img: 'http://qiniudns01.zhelan.net/map.png?imageView2/0/w/320/h/320',
				status: '',
				//投递状态 0快递收件(揽件)1.在途中 2.正在派件 3.已签收 4.派送失败 5.疑难件 6.退件签收
				statusList: [],
				hasStatus: false
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			var that = this;
			console.log(options);
			that.com = options.com;
			that.expresscode = options.expresscode;
			that.img = unescape(options.img);
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			var that = this;
			that.showLogistics();
		},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {
			uni.stopPullDownRefresh();
		},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function(res) {
			return {
				title: app.globalData.shareinfo.title,
				imageUrl: app.globalData.shareinfo.img,
				desc: app.globalData.shareinfo.desc,
				path: 'pages/index/index?Fid=' + uni.getStorageSync('uid')
				//点击分享的图片进到哪一个页面
			};
		},
		methods: {
			//查看物流信息
			showLogistics: function() {
				var that = this;
				var param = {};
				var url = 'SpSaleDelivery?token=' + uni.getStorageSync('token') + '&number=' + that.expresscode +
					'&name=' + that.com;
				api.requestAll(url, 'post', param, function(res) {
					console.log(res);
					if (res.data.Resp.RespCode == 100) {
						doLogin();
						uni.showToast({
							icon: 'none',
							title: '系统繁忙，请刷新重试！'
						});
						return;
					}
					if (res.data.Resp.RespCode != 0) {
						uni.showToast({
							icon: 'none',
							title: res.data.Resp.RespMsg
						});
						return;
					}
					var list = res.data.Data.List;
					var status = res.data.Data.deliverystatus;

					that.statusList = list;
					that.status = status == 0 ?
						'快递收件(揽件)' :
						status == 1 ?
						'在途中' :
						status == 2 ?
						'正在派件' :
						status == 3 ?
						'已签收' :
						status == 4 ?
						'派送失败' :
						status == 5 ?
						'疑难件' :
						'退件签收';
					if (null != list && list.length > 0) {
						that.hasStatus =  true;
					}
				});
			},

			backHome: function() {
				uni.switchTab({
					url: '/pages/index/index'
				});
			}
		}
	};
</script>
<style>
	@import './logistics.css';
</style>